package com.cskt.controller;

import com.cskt.entity.User;
import com.cskt.exception.BusinessException;
import com.cskt.response.Result;
import com.cskt.response.ResultCode;
import com.cskt.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 这是用来测试的Controller
 */
@RestController
@Slf4j
public class LogController {

    @Autowired
    private UserService userService;

    @GetMapping("/log")
    public Result log(){
        //int[] arr = {1,2,3,4};
        //System.out.println(arr[4]);

        //String a = null;
        //System.out.println(a.trim());

        //int i = 1/0;
        //数组越界

        User user = userService.getById(13);
        if(user==null){
            throw new BusinessException(ResultCode.USER_ACCOUNT_NOT_EXIST.getCode(),
                    ResultCode.USER_ACCOUNT_NOT_EXIST.getMessage());
        }
        log.info("打印info日志");
        return Result.ok().data("user",user);
    }
}
